package com.hong.day03.activiti;

import org.activiti.engine.*;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.runtime.ProcessInstanceQuery;
import org.activiti.engine.task.Task;

/**
 * @Auther: csh
 * @Date: 2019/11/21 18:38
 * @Description:全部流程实例挂起与激活
 */
public class SuspendProcessInstance2 {
    /*public static void main(String[] args) {
        //1.得到ProcessEngine对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到runtimeService
        RuntimeService runtimeService = defaultProcessEngine.getRuntimeService();
        //3.查询流程实例对象
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
                .processInstanceId("30001").singleResult();
        //4.得到当前流程定义的实例是否都为暂停状态
        boolean suspended = processInstance.isSuspended();

        String id = processInstance.getId();
        if(suspended){
            runtimeService.activateProcessInstanceById(id);;
            System.out.println("流程:"+id+"激活");
        }else{
            runtimeService.suspendProcessInstanceById(id);
            System.out.println("流程定义:"+id+"挂起");
        }
    }*/
    /**
     *
     * 功能描述:当流程实例 2501，已处于挂起状态，如果此时要让该实例继续执行，问题是:是否可以成功？
     *          如果不能执行，是否会抛出异常？cannot complete asuspend task
     *
     * @param:
     * @return:
     * @auther: csh
     * @date: 2019/11/22 16:05
     */
    public static void main(String[] args) {
        //1.得到ProcessEngine对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到TaskService对象
        TaskService taskService = defaultProcessEngine.getTaskService();
        //3.查询当前用户的任务
        Task task = taskService.createTaskQuery()
                .processDefinitionKey("holiday")
                .taskAssignee("zhangsan")
                .singleResult();
        //4.处理任务，结合当前用户任务列表的查询操作的话，任务ID task.getId()
        taskService.complete(task.getId());
        //5.输出任务的id
        System.out.println();

    }
}
